package entity;

/**
 * @Author: wanqian
 * @Date: 2021/2/4 23:45
 */
public class ArrBinaryTree {

    private int[] arr;

    public ArrBinaryTree(int[] arr) {
        this.arr = arr;
    }

    public void preOrder() {
        if (arr == null && arr.length == 0) {
            System.out.println("二叉树为空");
        }

        preOrder(0);
    }

    private void preOrder(int i) {
        System.out.println(arr[i]);

        if (2 * i + 1 < arr.length) {
            preOrder(2 * i + 1);
        }
        if (2 * i + 2 < arr.length) {
            preOrder(2 * i + 2);
        }
    }
}
